import React, { useEffect, useState } from 'react'

export default function Test () {
  const [count, setCount] = useState(10)
  useEffect(() => {
    const timer = setInterval(() => {
      // console.log(1);
      // 如何实时拿到更新之后的count
      setCount((count) => count - 1)
    }, 1000)
    return () => {
      // useEffect 第二个参数为空数组
      // 执行时机：组件卸载的时候
      clearInterval(timer)
    }
  }, [])
  useEffect(() => {
    // count更新之后
    console.log(count);
  }, [count])
  return (
    <div>
      <h2>{count}</h2>
    </div>
  )
}